package task

import (
	"fmt"
	"hft/Database/admin/phone"
	"hft/global"
	"hft/tools/phone/api"
	"hft/tools/phone/model"
	"strings"
	"time"
)

// 审核语音
type AudioAudit struct {
	Spec string
}

func (*AudioAudit) AuditPhoneAudio() {
	// 找出超过了1小时的楼盘然后添加
	var list []*phone.PhoneAudio
	global.OC_DB.Where("create_time < ?", (time.Now().Unix()-2*60*60)*1000).Not("audit = ?", 2).Find(&list)
	if len(list) != 0 {
		var modelList []*model.Row
		for _, v := range list {
			ani := fmt.Sprintf("%v_ani.wav", v.ID)
			dni := fmt.Sprintf("%v_dni.wav", v.ID)
			var newPhoneLen = strings.Split(v.Broker, ",")
			newPhone := strings.Join(newPhoneLen[1:len(newPhoneLen)-1], "|")
			modelList = append(modelList, &model.Row{Dn: fmt.Sprintf("%v", v.ID), AniVoiceName: ani, DniVoiceName: dni, Tel: newPhone})
		}
		if code := api.PhoneVirtual.AddOrEditPhone(modelList); code == "0" {
			// 如果添加成功则全部都改为已审核
			global.OC_DB.Model(&list).Update("audit", 2)
		}
	}
}

var AudioAuditSpec = &AudioAudit{Spec: "0 */30 * * *"}
